#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
调试Word文档表格结构
"""

from docx import Document

def debug_word_structure():
    """
    详细查看Word文档的表格结构
    """
    word_file = 'd:\\TCTaskSys\\设备维修记录单1.docx'
    
    try:
        doc = Document(word_file)
        
        print(f"文档包含 {len(doc.tables)} 个表格")
        
        for i, table in enumerate(doc.tables):
            print(f"\n=== 表格 {i+1} ===")
            print(f"行数: {len(table.rows)}, 列数: {len(table.columns)}")
            
            for j, row in enumerate(table.rows):
                print(f"\n行 {j+1}:")
                for k, cell in enumerate(row.cells):
                    cell_text = cell.text.strip()
                    print(f"  列 {k+1}: '{cell_text}'")
                    
                    # 特别关注确认人相关的单元格
                    if '确认' in cell_text or '确认人' in cell_text:
                        print(f"    *** 找到确认人相关字段: '{cell_text}' ***")
                        # 查看下一个单元格的内容
                        if k + 1 < len(row.cells):
                            next_cell = row.cells[k + 1].text.strip()
                            print(f"    *** 对应值: '{next_cell}' ***")
        
    except Exception as e:
        print(f"错误: {str(e)}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    debug_word_structure()